/// To reduce the risks of re-identification (please check raw to analysis do file), we have deleted children's age in month (childage) and children's nationality (natsyr) in the provided openly accessible dataset. Removing these variables would lower the number of cases running in the analyses (from 4313 to 4059) , but it would not affect the estimates in any statistically significant ways. 
/// However, you would find childage and natsyr in the current do file because this is the exact do file when we ran the analyses for the project. 
/// To re-run the data, simply delete childage and natsyr from the following codes. If you don't delete these two variables, you might find errors like "variable childage not found an error occurred when mi estimate executed xtmixed on m=1


**# Emotion strategies #
set maxvar 30000
use "ASdata_imputed"
foreach i in Code311Nothingnoreaction Code312Avoidant Code313Acceptance Code321Hitting  Code323Stealing Code324Ignoressafetyins  Code333Askforhelp Code334DeterminedBehavior Code335Findinganalternati Code336Playingcontinueto Code337RestingTakingabr Code338Sharing Code339Expressingkindword Code34Same Code411Nothingnoreaction Code412Avoidant Code413Acceptance Code414ReverseEmotionalRe  Code422Yelling Code423Stealing Code424Ignoressafetyins Code425AggressiveOther  Code432Dancing Code433Askforhelp Code434DeterminedBehavior Code435Findinganalternati Code436Playingcontinueto Code437RestingTakingabr Code438Sharing Code439Expressingkindword{
	
	 *no moderation
		mi estimate: xtmixed `i' i.tx ib3.n_gov i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS || schoolid: 
	*moderation by child's gender
		mi estimate: xtmixed `i' i.tx##i.childgender ib3.n_gov  i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS || schoolid: 
		*moderation by child's age
		mi estimate: xtmixed `i' i.tx##c.childage i.childgender ib3.n_gov  i.cg_gender  b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS || schoolid:
	
	*moderation by school governorate
		mi estimate: xtmixed `i' i.tx Al_Balqa Al_Karak tx_Al_Balqa tx_Al_Karak  i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid:
	mi test tx_Al_Balqa tx_Al_Karak
	*in irbid 
	mi estimate: xtmixed `i' i.tx i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid: if n_gov==3
	*in Al-Balqa
	mi estimate: xtmixed `i' i.tx i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid: if n_gov==1
	* in Al-Karak
	mi estimate: xtmixed `i' i.tx i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid: if n_gov==2

	
}

**# Emotion vocabularies, emotion situation knowledge, expressive and receptive emotion recognition skills  #
foreach i in  Code111Anger Code112Caring Code113Fear Code114Frustration Code115Nervousness Code116HopeDetermination Code117Jealousy  Code118Loneliness Code119Sadness Code1110Happiness quant_game1_mean quant_game2_mean correct_mention_asked correct_description correct_mention_later story_item1_valence   jealousy_asked jealousy_desc jealousy_later caring_asked caring_desc caring_later hope_asked hope_desc hope_later nervous_asked nervous_desc nervous_later lonely_asked lonely_desc lonely_later frustration_asked frustration_desc frustration_later jealousy_valence  caring_valence  hope_valence nervous_valence  lonely_valence  story7_item1_valence  quant_corr_g1_q1a quant_corr_g1_q2a quant_corr_g1_q3a quant_corr_g1_q4a quant_corr_g1_q5a quant_corr_g1_q6a quant_corr_game2_q1 quant_corr_game2_q2 quant_corr_game2_q3 quant_corr_game2_q4 quant_corr_game2_q5{
	
	 *no moderation
		mi estimate: xtmixed `i' i.tx ib3.n_gov i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS || schoolid: 
	*moderation by child's gender
		mi estimate: xtmixed `i' i.tx##i.childgender ib3.n_gov  i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS || schoolid: 
		*moderation by child's age
		mi estimate: xtmixed `i' i.tx##c.childage i.childgender ib3.n_gov  i.cg_gender  b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS || schoolid:
	
	*moderation by school's governorate
		mi estimate: xtmixed `i' i.tx Al_Balqa Al_Karak tx_Al_Balqa tx_Al_Karak  i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid:
	mi test tx_Al_Balqa tx_Al_Karak
	*in irbid 
	mi estimate: xtmixed `i' i.tx i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid: if n_gov==3
	*in Al-Balqa
	mi estimate: xtmixed `i' i.tx i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid: if n_gov==1
	* in Al-Karak
	mi estimate: xtmixed `i' i.tx i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid: if n_gov==2


	
}

**# AS specific knowledge #
foreach i in quant_likecharacter_mean{
	*no moderation
		mi estimate: xtmixed `i' i.tx ib3.n_gov i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS || schoolid: 
	*moderation by child's gender
		mi estimate: xtmixed `i' i.tx##i.childgender ib3.n_gov  i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS || schoolid: 
		*moderation by child's age
		mi estimate: xtmixed `i' i.tx##c.childage i.childgender ib3.n_gov  i.cg_gender  b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS || schoolid:
	
	*moderation by school's governorate
		mi estimate: xtmixed `i' i.tx Al_Balqa Al_Karak tx_Al_Balqa tx_Al_Karak  i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid:
	mi test tx_Al_Balqa tx_Al_Karak
	*in irbid 
	mi estimate: xtmixed `i' i.tx i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid: if n_gov==3
	*in Al-Balqa
	mi estimate: xtmixed `i' i.tx i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid: if n_gov==1
	* not converge in Al-Karak
	mi estimate: xtmixed `i' i.tx i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid: if n_gov==2
	
}
*not converge on m=72
mi estimate, imputations(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ///
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 ///
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 73 74 75 76 78 79 80 81 82 ///
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100): ///
 xtmixed quant_likecharacter_mean i.tx i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid: if n_gov==2


***implementation data
foreach i in quant_recognise_game7_mean quant_name_game7_mean AS_quant_basma_origin AS_quant_jad_origin AS_cha_or end_emotion_1 end_emotion_2 end_emotion_3 end_emotion_4 end_emotion_5 end_emotion_6 end_emotion_7 end_emotion_8 end_emotion_9 end_media_AS{
	
	 *no moderation
		mi estimate: xtmixed `i' i.tx ib3.n_gov i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS || schoolid: 
	*moderation by child's gender
		mi estimate: xtmixed `i' i.tx##i.childgender ib3.n_gov  i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS || schoolid: 
		*moderation by child's age
		mi estimate: xtmixed `i' i.tx##c.childage i.childgender ib3.n_gov  i.cg_gender  b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS || schoolid:
	
	*moderation by school's governorate
		mi estimate: xtmixed `i' i.tx Al_Balqa Al_Karak tx_Al_Balqa tx_Al_Karak  i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid:
	mi test tx_Al_Balqa tx_Al_Karak
	*in irbid 
	mi estimate: xtmixed `i' i.tx i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid: if n_gov==3
	*in Al-Balqa
	mi estimate: xtmixed `i' i.tx i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid: if n_gov==1
	* in Al-Karak
	mi estimate: xtmixed `i' i.tx i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid: if n_gov==2

	
}

**# bpm and asq #
mi estimate: xtmixed end_PSOC base_PSOC i.tx i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid: if n_gov==2

***explore
foreach i in COMM GMOT FMOT PSLV PSOC bpm_attention bpm_internal bpm_external{
 *no moderation
		mi estimate: xtmixed end_`i' base_`i' i.tx ib3.n_gov i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS || schoolid: 
	*moderation by child's gender
		mi estimate: xtmixed end_`i' base_`i' i.tx##i.childgender ib3.n_gov  i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS || schoolid: 
		*moderation by child's age
		mi estimate: xtmixed end_`i' base_`i' i.tx##c.childage i.childgender ib3.n_gov  i.cg_gender  b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS || schoolid:
	
	*moderation by school's governorate
		mi estimate: xtmixed end_`i' base_`i' i.tx Al_Balqa Al_Karak tx_Al_Balqa tx_Al_Karak  i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid:
	mi test tx_Al_Balqa tx_Al_Karak
	*in irbid 
	mi estimate: xtmixed end_`i' base_`i' i.tx i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid: if n_gov==3
	*in Al-Balqa
	mi estimate: xtmixed end_`i' base_`i' i.tx i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid: if n_gov==1
	* in Al-Karak
	mi estimate: xtmixed end_`i' base_`i' i.tx i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid: if n_gov==2
}

*end_PSOC not converge on moderation by governorate in Al-Balqa

*not converge on m=21
mi estimate, imputations(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 ///
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 ///
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 78 79 80 81 82 ///
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100): ///
 xtmixed end_PSOC base_PSOC i.tx i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid: if n_gov==1
 

 //double check our results with difference-in-difference tests
use "ASdata_imputed"
 gen timeline=.
foreach i in COMM GMOT FMOT PSLV PSOC bpm_attention bpm_internal bpm_external{
	mi rename base_`i'  `i'1
	mi rename end_`i' `i'2
	}

mi reshape long COMM GMOT FMOT PSLV PSOC bpm_attention bpm_internal bpm_external , i(hhid_cg_id_d) j(timeline)
save "ASdata_imputed_long"

foreach i in COMM GMOT FMOT PSLV PSOC bpm_attention bpm_internal bpm_external{
mi estimate: xtmixed `i' i.tx##i.timeline i.childgender i.cg_gender childage b_age i.natsyr Prei_fscore mics_mean pss_mean cg_educ_vf  hh_adnum hh_cnum cg_general_health childhealth ss_children ss_personal ss_house t_dm_teacher_educ  t_dm_yrs_teach  tcc_num_stdnts  media_AS|| schoolid: || hhid_cg_id_d:
}

